import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:audioplayers/audioplayers.dart';
import 'package:speed_random/app_styles.dart';
import 'package:speed_random/common/common_fuc.dart';
import 'package:speed_random/pages/home/rand_com/view_set.dart';
import 'package:speed_random/pages/home/spin_bottle/view_set.dart';
import 'package:speed_random/widgets/row_two_buttons.dart';

import 'logic.dart';
import 'state.dart';

class SpinBottlePage extends StatelessWidget {
  SpinBottlePage({Key? key}) : super(key: key);

  final SpinBottleLogic logic = Get.put(SpinBottleLogic());
  final SpinBottleState state = Get.find<SpinBottleLogic>().state;



  @override
  Widget build(BuildContext context) {

    return Scaffold(
      appBar: AppBar(
        title: Obx(()=>Text(state.randComArgs.value.title)),
       // backgroundColor: AppStyles.colorAppBarbg,
        actions: [
          /*IconButton(
            icon: const Icon(Icons.history),
            onPressed: () {
              Get.to(() => ComResultsPage(),arguments: Get.arguments); // 跳转到历史页面
            },
          ),*/
        ],
      ),
      body: Container(
         // color: AppStyles.colorAppBarbg, // 添加红色背景
          child:Padding(
            padding: const EdgeInsets.all(16.0),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.stretch,
              children: [
                // 显示当前设置
                Expanded(child:
            Card(
            color:state.randComArgs.value.colorPagebg,
            // 使用 Obx 响应式组件
            child:Center(
                  child: Column(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: [
                      Obx(() => Transform.rotate(
                        angle: state.rotationAngle.value,
                        child: Text(state.randComArgs.value.list,
                            style: TextStyle(fontSize: 150, color: Colors.blue)),
                      )),

                    ],
                  ),
                ),
            )
                ),
                const SizedBox(height: 10),


                /*底部状态按钮*/

                Obx(()=>rowRunOrSetButtons(
                  isRun:state.isRun.value ,
                  isManualStop:state.isManualStop.value ,
                  onGetRandomNumPressed: () {

                      logic.startRotation();


                    //logic.generateRandomNumbers();
                  },
                  onSettingsPressed: () {
                    // 导航到设置页面
                    Navigator.push(
                      context,
                      MaterialPageRoute(
                        builder: (context) => SettingsPageSpin(logic: logic, state: state),
                      ),
                    );
                    // showSettingsDialog(context);
                  },
                  onOkPressed: (){
                    state.isRun.value=0;
                  },
                  onStopPressed: (){
                    state.isRun.value=2;
                  },
                ),),
                /*底部状态按钮*/
                const SizedBox(height: 16),
              ],
            ),
          )),
    );
  }
}
